;( function( LoginControl )
 {
     var request = null;

     var KEY = document.getElementById("KEYHD");

     var sTarget = KEY.getAttribute("data-target");

     var iUserStatus = KEY.getAttribute("data-user");

     var PathCheckmac = KEY.getAttribute("data-checkmac");

     var matchLocalMac = function( array, local )
     {
         for( var i = 0; i < array.length; i += 1 )
         {
             if( array[ i ] == local )
             {
                 return i;
             }
         }

         return -1;
     }

     // 免费用户
     if( iUserStatus == 1 )  return false;

     var OPT = {
         plugName : "s_simnew61",
         keyUserName : "mingteng",
         keyPassWord : "mingteng",
         userNamePath : 0,
         macPath : [ 88, 108 ]
     };

     // 登录验证流程开始
     var Login = new LoginControl( OPT );

     Login.getDriver();

     // 判断驱动
     if( !Login.isInstallDriver() )
     {
         window.location.href = sTarget + "?tt=1";

         return false;
     }

     // 获取本地MAC
     var localMac = Login.getLocalMac();
     // KEY MAC
     var keyMac = Login.getKeyMac();

     // 付费用户
     if( iUserStatus == 2 )
     {
         // 检查是否插KEY
         Login.isKeyPnp( function( status )
         {
             if( status )
             {
                 if( keyMac.length )
                 {
                     // 本机使用
                     if( matchLocalMac( keyMac, localMac ) == -1 )
                     {
                        window.location.href = sTarget + "?tt=2";
                     }
                     else
                     {
                         // 发送请求
                         var callbackObject = {
                             success : function( res )
                             {
                                 if( res["status"] )
                                 {
                                    // alert("进入")
                                 }
                                 else
                                 {
                                     window.location.href = sTarget + "?tt=5";
                                 }
                             }
                         };

                         var sendData = { "mac": localMac  };

                         request && request.abort();

                         request = Handle.Request( "post", PathCheckmac, sendData, callbackObject, "json" );
                     }
                 }
                 // new K
                 else
                 {
                     window.location.href = sTarget + "?tt=3";
                 }
             }
             else
             {
                 window.location.href = sTarget + "?tt=4";
             }
         });

     }
     // 内部用户
     else if( iUserStatus == 3 )
     {
         // 发送请求
         var callbackObject = {
             success : function( res )
             {
                 if( res["status"] )
                 {
                     // alert("进入")
                 }
                 else
                 {
                    window.location.href = sTarget + "?tt=5";
                 }
             }
         };

         var sendData = { "mac": localMac  };

         request && request.abort();
         request = Handle.Request( "post", PathCheckmac, sendData, callbackObject, "json" );
     }

 })( LoginController );
